package demo4;

import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-07-31
 * Time: 10:45
 */
public class MyThreadPool {

    BlockingDeque<Runnable> blockingDeque = new LinkedBlockingDeque<>();

    public MyThreadPool(int n){
        for (int i = 0; i < n; i++) {
            Thread thread = new Thread(() ->{
                while (true){
                    try {
                        blockingDeque.take().run();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            thread.start();
        }
    }

    public void submit(Runnable runnable) throws InterruptedException {
        blockingDeque.put(runnable);
    }


}
